package org.gruposp2p.aula.gwt.client.content;

import org.gruposp2p.aula.gwt.client.AulaApplication;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.i18n.client.Constants;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;

public class ValidationErrorDialogBox extends DialogBox {
	
	public static interface CwConstants extends Constants {
		String ValidationErrorDialogBoxCaption();
		String ValidationErrorMessage();
		String AcceptButtonCaption();
	}
	  /**
	   * An instance of the constants.
	   */
	  private CwConstants constants;
	  //private FlexTable layout;
	
	public ValidationErrorDialogBox (AulaApplication aulaApplication) {
		constants = aulaApplication.getConstants();
        ensureDebugId("ValidationErrorDialogBox");
        showDialog();
	}
	
	private void showDialog () {
		setText(constants.ValidationErrorDialogBoxCaption());  
		FlexTable layout = new FlexTable(); 
		layout.clear();
	    layout.setCellSpacing(6);
	    layout.setWidth("250px");
	    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
	    
	    HTML errorMessage = new HTML(constants.ValidationErrorMessage());
	    layout.setWidget(0, 0, errorMessage);
	    TextBox nameTextBox = new TextBox ();
	    layout.setWidget(0, 1, nameTextBox);
	    layout.setHTML(1, 0, constants.ValidationErrorMessage());
	    layout.setWidget(1, 1, new TextBox());

	    Button acceptButton = new Button(constants.AcceptButtonCaption(),
		        new ClickHandler() {
		          public void onClick(ClickEvent event) {
		            hide();
		          }
		        });    

	    HorizontalPanel hPanel = new HorizontalPanel();
	    hPanel.setSpacing(5);
	    hPanel.add(acceptButton);

	    layout.setWidget(1, 1, hPanel);
	    cellFormatter.setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_RIGHT);
	    setWidget(layout);
	    //To solve Firefox strange effect
	    nameTextBox.setFocus(true);
	}

}